package cn.edu.scau.cmi.mengzhuorong.adapterOfObject;

import java.util.ArrayList;
import java.util.List;

import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.control.TextField;

import javafx.scene.control.Label;

public class AdapterOfObjectController extends AdapterOfObject {

	@FXML
	private TextField text_ID;
	@FXML
	private TextField text_name;
	@FXML
	private Label label_list;
	@FXML
	private Button btn_object;
	
	String  name;
	int ID;
	Student student =null;
	List<Student> studentListParent = new ArrayList<Student>();
	List<Integer> studentIdList = null;
	
	
	public void eventButton() {
		String NameList = null;
		ID = Integer.valueOf(text_ID.getText());
		name = text_name.getText();
		student = new Student(ID, name);
		studentListParent.add(student);
		if(studentListParent!=null) {
			studentIdList = studentList(studentListParent);
			studentIdList = sortInt(studentIdList);
		}
		for( int i = 0; i < studentListParent.size(); i++) {
			System.out.println(studentListParent.get(i).ID+" "+studentListParent.get(i).name);
		}
		
		for(int i = 0; i < studentIdList.size(); i++) {
			for(int j = 0; j < studentListParent.size(); j++) {
				if(studentListParent.get(j).ID == studentIdList.get(i)) {
					if(NameList == null)
					NameList = String.valueOf(studentListParent.get(j).ID) + " " + studentListParent.get(j).name+"\n";
					else NameList = NameList + String.valueOf(studentListParent.get(j).ID) + " " + studentListParent.get(j).name+"\n";
				}
			}
		}
		label_list.setText(NameList);
		
	}
}
